package com.ruoyi.active.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.active.domain.TActive;
import com.ruoyi.active.service.ITActiveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动，用于存储商品的活动信息Controller
 * 
 * @author ruoyi
 * @date 2024-11-11
 */
@RestController
@RequestMapping("/active/active")
public class TActiveController extends BaseController
{
    @Autowired
    private ITActiveService tActiveService;

    /**
     * 查询活动，用于存储商品的活动信息列表
     */
    @PreAuthorize("@ss.hasPermi('active:active:list')")
    @GetMapping("/list")
    public TableDataInfo list(TActive tActive)
    {
        startPage();
        List<TActive> list = tActiveService.selectTActiveList(tActive);
        return getDataTable(list);
    }

    /**
     * 导出活动，用于存储商品的活动信息列表
     */
    @PreAuthorize("@ss.hasPermi('active:active:export')")
    @Log(title = "活动，用于存储商品的活动信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TActive tActive)
    {
        List<TActive> list = tActiveService.selectTActiveList(tActive);
        ExcelUtil<TActive> util = new ExcelUtil<TActive>(TActive.class);
        util.exportExcel(response, list, "活动，用于存储商品的活动信息数据");
    }

    /**
     * 获取活动，用于存储商品的活动信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('active:active:query')")
    @GetMapping(value = "/{activeId}")
    public AjaxResult getInfo(@PathVariable("activeId") Long activeId)
    {
        return success(tActiveService.selectTActiveByActiveId(activeId));
    }

    /**
     * 新增活动，用于存储商品的活动信息
     */
    @PreAuthorize("@ss.hasPermi('active:active:add')")
    @Log(title = "活动，用于存储商品的活动信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TActive tActive)
    {
        return toAjax(tActiveService.insertTActive(tActive));
    }

    /**
     * 修改活动，用于存储商品的活动信息
     */
    @PreAuthorize("@ss.hasPermi('active:active:edit')")
    @Log(title = "活动，用于存储商品的活动信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TActive tActive)
    {
        return toAjax(tActiveService.updateTActive(tActive));
    }

    /**
     * 删除活动，用于存储商品的活动信息
     */
    @PreAuthorize("@ss.hasPermi('active:active:remove')")
    @Log(title = "活动，用于存储商品的活动信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activeIds}")
    public AjaxResult remove(@PathVariable Long[] activeIds)
    {
        return toAjax(tActiveService.deleteTActiveByActiveIds(activeIds));
    }
}
